﻿using AutoMapper;
using B.S.BasicData.Api.Read.Application.Command.Menu;
using B.S.BasicData.Api.Read.DTO;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.Menu
{
    public class GetBuFenMenuHandler : IRequestHandler<GetBuFenMenuCommand, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<RoleMenuModel> roleMenuRepo;
        private readonly IMapper mapper;

        public GetBuFenMenuHandler(IBaseRepository<RoleMenuModel> roleMenuRepo,IMapper mapper)
        {
            this.roleMenuRepo = roleMenuRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<int>>> Handle(GetBuFenMenuCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<int>> res = new ApiResult<List<int>>();
            var rolemenu = roleMenuRepo.GetAll().Where(x => x.Rid == request.Rid && !x.IsDelete).Select(x => x.Mid);
            res.Code = ApiEnum.Success;
            res.Data= rolemenu.ToList();
            res.Msg = "根据角色id查询菜单成功";
            return Task.FromResult(res);
        }
    }
}
